# @Author ZhangGJ
# @Date 2022/01/17 14:39
import time

import pymysql
from pymysql.cursors import DictCursor


# 导出海外注册用户
def export_user():
    conn = pymysql.connect(host='', port=3306, user='',
                           passwd='',
                           charset='utf8')
    cur = conn.cursor(DictCursor)
    query = 'select user_mobile from int_atoshi.atoshi_user where ip != "127.0.0.1"'
    cur.execute(query)
    user_list = cur.fetchall()
    now_time = 'user_mobile' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + '.txt'
    for user in user_list:
        user_mobile = dict(user).get('user_mobile')
        with open(now_time, 'a') as f:
            f.write(user_mobile)
            f.write('\n')
            f.close()


if __name__ == '__main__':
    export_user()
